Skip to content

Conversation

@kstasik
Copy link

@kstasik kstasik commented Dec 16, 2019

Error occurs when slave answers too quickly (race condition between write next() and listen handler). In my case: serial communication, baud rate 34800.

It tries to clearTimeout which doesn't exist yet.

In both cases 10 messages to same slave. It actually was repeatable in case of one message.

Before:

node test.js
2019-12-16T18:54:31.785Z << automaton-123 0x[ 0A, 03, 00, 00, 00, 01, 85, 71 ]
2019-12-16T18:54:31.802Z >> automaton-123 0x[ 0A, 03, 02, 00, 14, 1D, 8A ]
2019-12-16T18:54:31.806Z << automaton-123 0x[ 0A, 03, 00, 00, 00, 01, 85, 71 ]
response <Buffer 00 14>
2019-12-16T18:54:31.815Z >> automaton-123 0x[ 0A, 03, 02 ]
2019-12-16T18:54:31.816Z >> automaton-123 0x[ 00, 14, 1D ]
2019-12-16T18:54:31.817Z >> automaton-123 0x[ 8A ]
2019-12-16T18:54:31.819Z << automaton-123 0x[ 0A, 03, 00, 00, 00, 01, 85, 71 ]
response <Buffer 00 14>
2019-12-16T18:54:31.823Z >> automaton-123 0x[ 0A ]
2019-12-16T18:54:31.824Z >> automaton-123 0x[ 03, 02 ]
2019-12-16T18:54:31.824Z >> automaton-123 0x[ 00 ]
2019-12-16T18:54:31.825Z >> automaton-123 0x[ 14, 1D ]
2019-12-16T18:54:31.825Z >> automaton-123 0x[ 8A ]
2019-12-16T18:54:31.825Z << automaton-123 0x[ 0A, 03, 00, 00, 00, 01, 85, 71 ]
response <Buffer 00 14>
2019-12-16T18:54:31.829Z >> automaton-123 0x[ 0A ]
2019-12-16T18:54:31.830Z >> automaton-123 0x[ 03 ]
2019-12-16T18:54:31.830Z >> automaton-123 0x[ 02, 00 ]
2019-12-16T18:54:31.831Z >> automaton-123 0x[ 14 ]
2019-12-16T18:54:31.831Z >> automaton-123 0x[ 1D, 8A ]
2019-12-16T18:54:31.831Z << automaton-123 0x[ 0A, 03, 00, 00, 00, 01, 85, 71 ]
response <Buffer 00 14>
2019-12-16T18:54:31.843Z >> automaton-123 0x[ 0A, 03, 02, 00, 14, 1D, 8A ]
2019-12-16T18:54:31.843Z << automaton-123 0x[ 0A, 03, 00, 00, 00, 01, 85, 71 ]
response <Buffer 00 14>
2019-12-16T18:54:31.853Z >> automaton-123 0x[ 0A, 03, 02, 00, 14, 1D, 8A ]
2019-12-16T18:54:31.853Z << automaton-123 0x[ 0A, 03, 00, 00, 00, 01, 85, 71 ]
response <Buffer 00 14>
2019-12-16T18:54:31.857Z >> automaton-123 0x[ 0A ]
2019-12-16T18:54:31.858Z >> automaton-123 0x[ 03 ]
2019-12-16T18:54:31.858Z >> automaton-123 0x[ 02, 00 ]
2019-12-16T18:54:31.858Z >> automaton-123 0x[ 14 ]
2019-12-16T18:54:31.859Z >> automaton-123 0x[ 1D ]
2019-12-16T18:54:31.859Z >> automaton-123 0x[ 8A ]
2019-12-16T18:54:31.859Z << automaton-123 0x[ 0A, 03, 00, 00, 00, 01, 85, 71 ]
response <Buffer 00 14>
2019-12-16T18:54:31.863Z >> automaton-123 0x[ 0A, 03 ]
2019-12-16T18:54:31.864Z >> automaton-123 0x[ 02 ]
2019-12-16T18:54:31.864Z >> automaton-123 0x[ 00 ]
2019-12-16T18:54:31.864Z >> automaton-123 0x[ 14, 1D ]
2019-12-16T18:54:31.865Z >> automaton-123 0x[ 8A ]
2019-12-16T18:54:31.865Z << automaton-123 0x[ 0A, 03, 00, 00, 00, 01, 85, 71 ]
response <Buffer 00 14>
2019-12-16T18:54:31.873Z >> automaton-123 0x[ 0A, 03, 02, 00, 14, 1D, 8A ]
2019-12-16T18:54:31.873Z << automaton-123 0x[ 0A, 03, 00, 00, 00, 01, 85, 71 ]
response <Buffer 00 14>
Error GatewayTargetDeviceFailedToRespond
2019-12-16T18:54:31.883Z >> automaton-123 0x[ 0A, 03, 02, 00, 14, 1D, 8A ]
response <Buffer 00 14>
Error GatewayTargetDeviceFailedToRespond
Error GatewayTargetDeviceFailedToRespond
Error GatewayTargetDeviceFailedToRespond

But it actually receives correct responses from device in all cases.

After:

node test.js
2019-12-16T18:56:40.679Z << automaton-123 0x[ 0A, 03, 00, 00, 00, 01, 85, 71 ]
2019-12-16T18:56:40.696Z >> automaton-123 0x[ 0A, 03, 02, 00, 14, 1D, 8A ]
2019-12-16T18:56:40.700Z << automaton-123 0x[ 0A, 03, 00, 00, 00, 01, 85, 71 ]
response <Buffer 00 14>
2019-12-16T18:56:40.709Z >> automaton-123 0x[ 0A, 03, 02 ]
2019-12-16T18:56:40.710Z >> automaton-123 0x[ 00, 14, 1D ]
2019-12-16T18:56:40.711Z >> automaton-123 0x[ 8A ]
2019-12-16T18:56:40.712Z << automaton-123 0x[ 0A, 03, 00, 00, 00, 01, 85, 71 ]
response <Buffer 00 14>
2019-12-16T18:56:40.717Z >> automaton-123 0x[ 0A ]
2019-12-16T18:56:40.717Z >> automaton-123 0x[ 03 ]
2019-12-16T18:56:40.717Z >> automaton-123 0x[ 02, 00 ]
2019-12-16T18:56:40.718Z >> automaton-123 0x[ 14 ]
2019-12-16T18:56:40.718Z >> automaton-123 0x[ 1D ]
2019-12-16T18:56:40.718Z >> automaton-123 0x[ 8A ]
2019-12-16T18:56:40.718Z << automaton-123 0x[ 0A, 03, 00, 00, 00, 01, 85, 71 ]
response <Buffer 00 14>
2019-12-16T18:56:40.722Z >> automaton-123 0x[ 0A ]
2019-12-16T18:56:40.723Z >> automaton-123 0x[ 03 ]
2019-12-16T18:56:40.723Z >> automaton-123 0x[ 02, 00 ]
2019-12-16T18:56:40.724Z >> automaton-123 0x[ 14 ]
2019-12-16T18:56:40.724Z >> automaton-123 0x[ 1D, 8A ]
2019-12-16T18:56:40.724Z << automaton-123 0x[ 0A, 03, 00, 00, 00, 01, 85, 71 ]
response <Buffer 00 14>
2019-12-16T18:56:40.728Z >> automaton-123 0x[ 0A ]
2019-12-16T18:56:40.729Z >> automaton-123 0x[ 03 ]
2019-12-16T18:56:40.729Z >> automaton-123 0x[ 02 ]
2019-12-16T18:56:40.729Z >> automaton-123 0x[ 00 ]
2019-12-16T18:56:40.730Z >> automaton-123 0x[ 14, 1D ]
2019-12-16T18:56:40.730Z >> automaton-123 0x[ 8A ]
2019-12-16T18:56:40.730Z << automaton-123 0x[ 0A, 03, 00, 00, 00, 01, 85, 71 ]
response <Buffer 00 14>
2019-12-16T18:56:40.734Z >> automaton-123 0x[ 0A ]
2019-12-16T18:56:40.735Z >> automaton-123 0x[ 03 ]
2019-12-16T18:56:40.735Z >> automaton-123 0x[ 02, 00 ]
2019-12-16T18:56:40.735Z >> automaton-123 0x[ 14 ]
2019-12-16T18:56:40.736Z >> automaton-123 0x[ 1D ]
2019-12-16T18:56:40.736Z >> automaton-123 0x[ 8A ]
2019-12-16T18:56:40.736Z << automaton-123 0x[ 0A, 03, 00, 00, 00, 01, 85, 71 ]
response <Buffer 00 14>
2019-12-16T18:56:40.740Z >> automaton-123 0x[ 0A ]
2019-12-16T18:56:40.741Z >> automaton-123 0x[ 03 ]
2019-12-16T18:56:40.741Z >> automaton-123 0x[ 02 ]
2019-12-16T18:56:40.741Z >> automaton-123 0x[ 00 ]
2019-12-16T18:56:40.741Z >> automaton-123 0x[ 14 ]
2019-12-16T18:56:40.742Z >> automaton-123 0x[ 1D ]
2019-12-16T18:56:40.742Z >> automaton-123 0x[ 8A ]
2019-12-16T18:56:40.742Z << automaton-123 0x[ 0A, 03, 00, 00, 00, 01, 85, 71 ]
response <Buffer 00 14>
2019-12-16T18:56:40.746Z >> automaton-123 0x[ 0A ]
2019-12-16T18:56:40.746Z >> automaton-123 0x[ 03 ]
2019-12-16T18:56:40.747Z >> automaton-123 0x[ 02 ]
2019-12-16T18:56:40.747Z >> automaton-123 0x[ 00 ]
2019-12-16T18:56:40.747Z >> automaton-123 0x[ 14 ]
2019-12-16T18:56:40.747Z >> automaton-123 0x[ 1D ]
2019-12-16T18:56:40.748Z >> automaton-123 0x[ 8A ]
2019-12-16T18:56:40.748Z << automaton-123 0x[ 0A, 03, 00, 00, 00, 01, 85, 71 ]
response <Buffer 00 14>
2019-12-16T18:56:40.752Z >> automaton-123 0x[ 0A ]
2019-12-16T18:56:40.752Z >> automaton-123 0x[ 03 ]
2019-12-16T18:56:40.753Z >> automaton-123 0x[ 02 ]
2019-12-16T18:56:40.753Z >> automaton-123 0x[ 00 ]
2019-12-16T18:56:40.753Z >> automaton-123 0x[ 14 ]
2019-12-16T18:56:40.753Z >> automaton-123 0x[ 1D ]
2019-12-16T18:56:40.754Z >> automaton-123 0x[ 8A ]
2019-12-16T18:56:40.754Z << automaton-123 0x[ 0A, 03, 00, 00, 00, 01, 85, 71 ]
response <Buffer 00 14>
2019-12-16T18:56:40.758Z >> automaton-123 0x[ 0A ]
2019-12-16T18:56:40.758Z >> automaton-123 0x[ 03 ]
2019-12-16T18:56:40.759Z >> automaton-123 0x[ 02 ]
2019-12-16T18:56:40.759Z >> automaton-123 0x[ 00 ]
2019-12-16T18:56:40.759Z >> automaton-123 0x[ 14 ]
2019-12-16T18:56:40.759Z >> automaton-123 0x[ 1D ]
2019-12-16T18:56:40.760Z >> automaton-123 0x[ 8A ]
response <Buffer 00 14>

@kstasik kstasik changed the title fix: race condition fixed when slave answers to quickly causing GatewayTargetDeviceFailedToRespond fix: race condition fixed when slave answers too quickly causing GatewayTargetDeviceFailedToRespond Dec 16, 2019
@kstasik
Copy link
Author

kstasik commented Dec 16, 2019

Please let me know if you know better way to fix this race condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant